package com.electromagnetic.industry.software.manage.controller;

import cn.hutool.core.lang.Assert;
import com.electromagnetic.industry.software.common.annotations.UserOperation;
import com.electromagnetic.industry.software.common.enums.AdminTypeEnum;
import com.electromagnetic.industry.software.common.enums.UserOperationModuleEnum;
import com.electromagnetic.industry.software.common.resp.ElectromagneticResult;
import com.electromagnetic.industry.software.common.util.UserThreadLocal;
import com.electromagnetic.industry.software.manage.pojo.req.AccessLogQueryDTO;
import com.electromagnetic.industry.software.manage.service.UserAccessLogService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/data/ed/log/")
public class AccessLogController {

    @Resource
    private UserAccessLogService userAccessLogService;

    @UserOperation(value = "查看操作记录", modelName = UserOperationModuleEnum.LOG)
    @RequestMapping("file")
    public ElectromagneticResult<?> file(@RequestBody AccessLogQueryDTO accessLogQueryDTO) {
        accessLogQueryDTO.setPageNum(accessLogQueryDTO.getPageIndex());
        return userAccessLogService.info(accessLogQueryDTO, false);
    }


    @UserOperation(value = "查看审计", modelName = UserOperationModuleEnum.LOG)
    @RequestMapping("audit")
    public ElectromagneticResult<?> audit(@RequestBody AccessLogQueryDTO accessLogQueryDTO) {
        Assert.isTrue(UserThreadLocal.getAdminType().equals(AdminTypeEnum.AUDIT.getValue()), "当前用户没有查看审计的权限");
        return userAccessLogService.info(accessLogQueryDTO, true);
    }

    @UserOperation(value = "查询所有操作对象", modelName = UserOperationModuleEnum.LOG)
    @RequestMapping("operation/module")
    public ElectromagneticResult<?> operationModule() {
        return userAccessLogService.operationModule();
    }

}
